import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from 'view/users/login'
import MainLayout from 'lay/MainLayout'
import store from 'store';
Vue.use(VueRouter)

const routes = [
  {
    name: 'MainLayout',
    path: '/',
    component: MainLayout
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to, from, next) => {
//   const token = store.getters.token
//   const isLogin = to.name === 'login'
//   if (token && isLogin) return next({ name: 'MainLayout' })
//   if (!token && !isLogin) return next({ name: 'login' })
//   next()
// })

export default router
